import { createStore } from 'vuex'
import settings from './modules/settings'
import app from './modules/app'

function getData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('success')
    }, 1000)
  })
}

export default createStore({
  modules: {
    account: {
      namespaced: true,
      state: () => ({
        user: 'zhaomeiyang',
        age: 20,
        sex: 'male'
      }),
      mutations: {
        login(state, n) {
          state.user = n
        }
      },
      actions: {
        async login({commit, state}, payload) {
          console.log(payload, 'payload')
          let res = await getData()
          commit('login', res)
        }
      },
      getters: {
        myName(state) {
          return state.user
        }
      }
    },
    settings,
    app
  }
})
